package com.gjy.mybatis.plugin;

import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.plugin.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Method;
import java.sql.Statement;
import java.util.Properties;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-10-07 09:12:09
 */
@Intercepts({
        @Signature(type = StatementHandler.class, method = "update", args = {Statement.class})
})
public class ExamplePlugin implements Interceptor {

    private static final Logger log = LoggerFactory.getLogger(ExamplePlugin.class);

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        Object target = invocation.getTarget();
        Method method = invocation.getMethod();
        Object[] args = invocation.getArgs();
        Object proceed = invocation.proceed();
        log.info("proceed {},{}", proceed, proceed.getClass());
        return proceed;
    }

    @Override
    public Object plugin(Object target) {
        return Plugin.wrap(target, this);
    }

    @Override
    public void setProperties(Properties properties) {
        String type = properties.getProperty("type");
        String start = properties.getProperty("start");
        log.info("type={}, start={}", type, start);
    }

}
